package com.feidee.bigdata.bloomfilterserv.schedule;

import com.feidee.bigdata.bloomfilterserv.constant.Constant;
import com.feidee.bigdata.bloomfilterserv.dao.IBloomFilterDao;
import com.feidee.bigdata.bloomfilterserv.util.ToolUtils;
import com.feidee.fdfalcon.falcon.FalconAlarmService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

@Component
@EnableScheduling
public class ScheduleJob {

	@Autowired
	private IBloomFilterDao bloomFilterDao;

	private Logger logger = LoggerFactory.getLogger(ScheduleJob.class);
	private static String LAST_RECORD_DAY = ToolUtils.getCurrentDay();

	@Scheduled(cron = "2 0 0/4 * * ?")  //每4小时执行一次
	public void refreshBl() {

		String currentDay = ToolUtils.getCurrentDay();
		if (!LAST_RECORD_DAY.equals(currentDay)) {
			bloomFilterDao.clearBF();
			LAST_RECORD_DAY = currentDay;
			logger.info(">>>>>>>>> " + currentDay + " : 删除当前内存记录布隆过滤器内容，清空重新记录... <<<<<<<<<<<");
			logger.info("该布隆服务器当天调用总次数：" + Constant.LOG_PRINT_CNT);
			Constant.LOG_PRINT_CNT = 0; //清零日志打印次数
			FalconAlarmService.sendAlarm("布隆服务:" + Constant.UUID_IP_PREFIX + " 清除当天布隆过滤器内容成功", "bloomfilterAlarm");
		} else {
			logger.info(">>>>>>>>> " + currentDay + " : 未到清除布隆过滤器时间，继续等待下一次... <<<<<<<<<<<");
		}

	}

}
